package com.ctl.szmd.szmd.feature_wm.ui.binding

import android.view.View
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.ctl.lib_common.extensions.dpToPx
import com.ctl.lib_common.widget.glide.CenterCropRoundCornerTransform
import com.ctl.szmd.szmd.feature_wm.R
import com.ctl.szmd.szmd.feature_wm.data.model.WmDataListModel


/**
 * created by : chentl
 * Date: 2020/07/20
 */

@BindingAdapter("bindingImage")
fun bindingImage(imageView: ImageView, url: String) {
}

@BindingAdapter("bindingRoundAvatarImage")
fun bindingRoundAvatarImage(imageView: ImageView, url: String?) {
    val option = RequestOptions()
        .placeholder(R.drawable.bg_gr_mrtx)
        .transform(CircleCrop())
    Glide.with(imageView.context)
        .load(url)
        .apply(option)
        .into(imageView)

}

@BindingAdapter("bindingWmRememberImageViewSrc")
fun bindingWmRememberImageViewSrc(imageView: ImageView, isRemember: Boolean) {
    if (isRemember) {
        imageView.setImageResource(R.drawable.wm_icon_xz_pressed)
    } else {
        imageView.setImageResource(R.drawable.wm_icon_xz_normal)
    }
}

@BindingAdapter("bindingClick2FileDisplay")
fun bindingClick2FileDisplay(view: View, model: WmDataListModel) {

}

@BindingAdapter("bindingWmImageNews")
fun bindingWmImageNews(imageView: ImageView, url: String?) {
    if (url.isNullOrEmpty()) {
        imageView.visibility = View.GONE
    } else {
        imageView.visibility = View.VISIBLE

        val options = RequestOptions()
            .placeholder(R.drawable.wm_bg_morentu_liebiao)
            .centerCrop()
            .transform(
                CenterCropRoundCornerTransform(
                    4.dpToPx
                )
            )
        Glide.with(imageView.context)
            .load(url)
//            .apply(options)
//            .thumbnail(
//                Glide.with(imageView.context)
//                    .load(R.drawable.wm_bg_morentu_liebiao)
//                    .apply(
//                        RequestOptions()
//                            .centerCrop()
//                            .transform(
//                                CenterCropRoundCornerTransform(
//                                    4.dpToPx
//                                )
//                            )
//                    )
//            )
            .into(imageView)
    }
}

@BindingAdapter("bindingWmHomeBanner")
fun bindingWmHomeBanner(imageView: ImageView, url: String?) {
    Glide.with(imageView.context)
        .load(url)
        .centerCrop()
        .placeholder(R.drawable.wm_bg_morentu_liebiao)
        .into(imageView)

}
